package com.zhixi.pattern.important.singletonpattern.operation;

/**
 * 双重检查（推荐）
 *
 *
 * @作者 ShuHaoNan
 * @邮箱 shuhaonan1@gmail.com
 * @时间 2020/11/15 9:33
 */
public class Singleton6 {

    private static volatile Singleton6 instance;

    private Singleton6() {}

    // 双重检查
    public static synchronized Singleton6 getInstance() {
        if (instance == null) {
            synchronized (Singleton6.class) {
                if (instance == null) {
                    instance = new Singleton6();
                }
            }
        }
        return instance;
    }

}
